<template>
    <div id="app">
        <router-view />
    </div>
</template>
<script>
    import {

        getUrl2,
        getUrl1
    } from '@/api/data.js';
    export default {
        name: 'App',
        async  created() {
           await   this.getUser()
           this.getCityArr()
        },
        mounted() {
            // 默认修改title
            let title = this.$route.meta.title
            if (title) {
                document.title = title
            }
        },
        methods: {
            getUser() {
                // this.$store.commit("ADDDCITY", "合肥");
                return new Promise((resolve,reject)=>{
                    getUrl2("/api/user/getLoginUser")
                        .then((query) => {
                            if (query.success) {
                                this.$store.commit("ADDDCITY", query.body.fullRegionName);
                            } else {
                                this.$message.error('查询失败！')
                            }
                            resolve(query)
                        })
                        .catch((error) => {

                        })
                })

            },

            getCityArr() {
                 // let cityArr= [{
                //      regionName:"合肥"
                //  },{
                //      regionName:"六安"
                //  }];
                // this.$store.commit("ADDCITYARR", cityArr.filter(item=>item.regionName=='合肥'));
                getUrl1("/wir/code/getPrePlanCode")
                    .then((query) => {
                        if (query.success) {
                            let city=this.$store.state.city;
                            let cityArr= query.body.city;
                            if(city && city!=='浙江' ){
                                this.$store.commit("ADDCITYARR", cityArr.filter(item=>item.regionName==city));
                            }

                            if(city && city=='浙江' ){
                                this.$store.commit("ADDCITYARR", cityArr);
                            }


                        } else {
                            this.$message.error('查询失败！')
                        }
                    })
                    .catch((error) => {

                    })
            }
        }
    }
</script>

<style lang="scss">
    // 引入修改全局滚动条样式
    @import 'oss-common/css/customScrollBar.scss';

    #app {
        margin: 0;
        padding: 0;
    }
</style>
